package com.collection.vectors;

import java.util.Vector;

public class RemoveElementFromVectorByObjectExample {
	 public static void main(String[] args) {
		    //create a Vector object
		    Vector v = new Vector();
		   
		    //Add elements to Vector
		    v.add("1");
		    v.add("2");
		    v.add("3");
		    v.add("4");
		    v.add("5");
		   
		    /*
		      To remove a specified element from Vector use
		      boolean remove(Object o) method. It removes the first occurrence of
		      the object if found in the Vector. If not, Vector remains unchanged.
		      It returns true if Vector contained the specified object.
		    */
		    boolean blnElementFound = v.remove("2");
		    System.out.println("Was 2 removed from Vector ? " + blnElementFound);
		   
		    System.out.println("Vector contents after remove call...");
		    //display elements of Vector
		    for(int index=0; index < v.size(); index++)
		      System.out.println(v.get(index));
		   
		    /*
		       boolean removeElement(Object o) is also identical to the remove method.
		    */
		    v.removeElement("3");
		 
		    System.out.println("Was 3 removed from Vector ? " + blnElementFound);
		    System.out.println("Vector contents after removeElement call...");
		    //display elements of Vector
		    for(int index=0; index < v.size(); index++)
		      System.out.println(v.get(index));
		   
		   
		  }
}
